package com.linkdood.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkdood.app.domain.UserOrganization;
import com.linkdood.app.mapper.UserOrganizationMapper;
import com.linkdood.app.service.UserOrganizationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户和组织部门关系
 *
 * @author hycao
 */
@Slf4j
@Service
public class UserOrganizationServiceImpl extends ServiceImpl<UserOrganizationMapper, UserOrganization> implements UserOrganizationService {

    /**
     * 获取用户 id 的所有部门
     *
     * @return List<UserOrganization>
     * @param userId 用户 id
     */
    @Override
    public List<UserOrganization> listByUserId(String userId) {
        return lambdaQuery().eq(UserOrganization::getUserId, userId).list();
    }

    /**
     * 获取部门 id 的所有人员
     *
     * @return List<UserOrganization>
     * @param orgId 部门 id
     */
    @Override
    public List<UserOrganization> listByOrgId(String orgId) {
        return lambdaQuery().eq(UserOrganization::getOrgId, orgId).list();
    }

    /**
     * 删除部门人员关联信息
     * @param userId 用户 id
     */
    @Override
    public boolean deleteByUserId(String userId) {
        return lambdaUpdate().eq(UserOrganization::getUserId, userId).remove();
    }
}
